home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Games / Soundboard / CSoundboardWindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  6.2 KB  |  219 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CSoundboardWindow.cp        ©1995 Apple Comptuer, Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    A "do nothing" Soundboard program that you can use as a starter for
  6. //    you own programs.
  7.  
  8. #include "CSoundboardWindow.h"
  9.  
  10. // ===========================================================================
  11. //        • CSoundboardWindow Class
  12. // ===========================================================================
  13.  
  14. // ---------------------------------------------------------------------------
  15. //        • CSoundboardWindow
  16. // ---------------------------------------------------------------------------
  17. //    Constructor
  18.  
  19. CSoundboardWindow::CSoundboardWindow(LStream *inStream) : LWindow(inStream)
  20. {
  21. }
  22.  
  23.  
  24. // ---------------------------------------------------------------------------
  25. //        • ~CSoundboardWindow
  26. // ---------------------------------------------------------------------------
  27. //    Destructor
  28.  
  29. CSoundboardWindow::~CSoundboardWindow()
  30. {
  31.         // +++ Add code here to cleanup (if necessary) before quitting
  32. }
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        • CreateWindow
  36. // ---------------------------------------------------------------------------
  37. //    Return a newly created Window object initialized from a PPob resource
  38.  
  39. CSoundboardWindow*
  40. CSoundboardWindow::CreateSoundboardWindow(
  41.     ResIDT        inWindowID,
  42.     LCommander    *inSuperCommander)
  43. {
  44.     return ((CSoundboardWindow*)LWindow::CreateWindow(inWindowID, inSuperCommander));
  45. }
  46.  
  47.  
  48. // ---------------------------------------------------------------------------
  49. //        • CreateWindowStream
  50. // ---------------------------------------------------------------------------
  51. //    Return a newly created Window object initialized with data from a Stream
  52.  
  53. CSoundboardWindow*
  54. CSoundboardWindow::CreateSoundboardWindowStream(
  55.     LStream    *inStream)
  56. {
  57.     return (new CSoundboardWindow(inStream));
  58. }
  59.  
  60.  
  61. // ---------------------------------------------------------------------------
  62. //        • AttemptClose
  63. // ---------------------------------------------------------------------------
  64. //    Try to hide a Window as a result of direct user action
  65.  
  66. void
  67. CSoundboardWindow::AttemptClose()
  68. {
  69.                                     // Get approval from SuperCommander
  70.     if ((mSuperCommander == nil) || mSuperCommander->AllowSubRemoval(this)) {
  71.          
  72.                                      // Send Close AE for recording only
  73.         SendSelfAE(kAECoreSuite, kAEClose, false);
  74.         Hide();
  75.     }
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------
  80. //        • DoClose
  81. // ---------------------------------------------------------------------------
  82. //    Hide a Window
  83.  
  84. void
  85. CSoundboardWindow::DoClose()
  86. {
  87.                                     // Get approval from SuperCommander
  88.     if ((mSuperCommander == nil) || mSuperCommander->AllowSubRemoval(this)) {
  89.         Hide();
  90.     }
  91. }
  92.  
  93.  
  94. // ---------------------------------------------------------------------------
  95. //        • ObeyCommand
  96. // ---------------------------------------------------------------------------
  97. //    Respond to commands
  98.  
  99. Boolean
  100. CSoundboardWindow::ObeyCommand(
  101.     CommandT    inCommand,
  102.     void        *ioParam)
  103. {
  104.     Boolean    cmdHandled = true;
  105.     
  106.     switch (inCommand) {
  107.     
  108.         // +++ Add cases here for the commands you handle
  109.         //        Remember to add same cases to FindCommandStatus below
  110.         //        to enable/disable the menu items for the commands
  111.         default:
  112.             cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  113.             break;
  114.     }
  115.     
  116.     return cmdHandled;
  117. }
  118.  
  119.  
  120. // ---------------------------------------------------------------------------
  121. //        • FindCommandStatus
  122. // ---------------------------------------------------------------------------
  123. //    Pass back status of a (menu) command
  124.  
  125. void
  126. CSoundboardWindow::FindCommandStatus(
  127.     CommandT    inCommand,
  128.     Boolean        &outEnabled,
  129.     Boolean        &outUsesMark,
  130.     Char16        &outMark,
  131.     Str255        outName)
  132. {
  133.     switch (inCommand) {
  134.     
  135.         // +++ Add cases here for the commands you handle.
  136.         //
  137.         //        Set outEnabled to TRUE for commands that can be executed at
  138.         //        this time.
  139.         //
  140.         //        If the associated menu items can have check marks, set
  141.         //        outUsesMark and outMark accordingly.
  142.         //
  143.         //        Set outName to change the name of the menu item
  144.         default:
  145.             LWindow::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  146.                                 outMark, outName);
  147.             break;
  148.     }
  149. }
  150.  
  151. // ---------------------------------------------------------------------------
  152. //        • Show
  153. // ---------------------------------------------------------------------------
  154. //    Show the soundboard window
  155.  
  156. void
  157. CSoundboardWindow::Show()
  158. {
  159.     Select();
  160.     LWindow::Show();
  161. }
  162.  
  163. // ---------------------------------------------------------------------------
  164. //        • ClickInContent
  165. // ---------------------------------------------------------------------------
  166. //    Respond to a click in the content region of a Window
  167.  
  168. void
  169. CSoundboardWindow::ClickInContent(
  170.     const EventRecord    &inMacEvent)
  171. {
  172.                                     // Enabled Windows respond to clicks
  173.     Boolean        respondToClick = HasAttribute(windAttr_Enabled);
  174.     
  175.                                     // Set up our extended event record
  176.     SMouseDownEvent        theMouseDown;
  177.     theMouseDown.wherePort = inMacEvent.where;
  178.     GlobalToPortPoint(theMouseDown.wherePort);
  179.     theMouseDown.whereLocal = theMouseDown.wherePort;
  180.     theMouseDown.macEvent = inMacEvent;
  181.     theMouseDown.delaySelect = false;
  182.     
  183.     if (!UDesktop::WindowIsSelected(this)) {
  184.                                     // Window is not in front, we might
  185.                                     //   need to select it
  186.         Boolean    doSelect = false;
  187.         if (HasAttribute(windAttr_DelaySelect)) {
  188.                                     // Delay selection until after handling
  189.                                     //   the click (called click-through)
  190.             theMouseDown.delaySelect = true;
  191.             Click(theMouseDown);
  192.             
  193.                                     // After click-through, we select the
  194.                                     //   Window if the mouse is still down
  195.                                     //   or the mouse up occurred inside
  196.                                     //   this Window.
  197.             EventRecord    mouseUpEvent;
  198.             if (!::StillDown() && ::GetOSEvent(mUpMask, &mouseUpEvent)) {
  199.                                     // Check location of mouse up event
  200.                 WindowPtr    upWindow;
  201.                 ::FindWindow(mouseUpEvent.where, &upWindow);
  202.                 doSelect = (upWindow == mMacWindowP);
  203.             }
  204.         }
  205.         
  206.         if (doSelect) {                // Selecting a Window brings it to the
  207.                                     //   front of its layer and activates it
  208.             Select();
  209.             respondToClick = HasAttribute(windAttr_GetSelectClick);
  210.         }
  211.     }
  212.     
  213.     if (respondToClick && !theMouseDown.delaySelect) {
  214.         theMouseDown.delaySelect = false;
  215.         Click(theMouseDown);
  216.     }
  217. }
  218.  
  219.